package com.loong.system.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.common.validator.group.CommonValidate;
import com.loong.system.common.backend.param.SystemConfigKeyParam;
import com.loong.system.common.backend.param.SystemConfigKeyQueryParam;
import com.loong.system.handler.SystemConfigKeyHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 配置key控制器
 */
@RestController
@RequestMapping("/manage/system/configKey")
public class SystemConfigKeyController extends BaseBackendController {
    @Resource
    private SystemConfigKeyHandler systemConfigKeyHandler;

    /**
     * 保存key
     * @param param
     * @return
     */
    @PostMapping("save")
    public Result save(@Validated(value = {CommonInsert.class, CommonValidate.class}) SystemConfigKeyParam param){
        param.setId(null);
        return   handlerExecutor.execute(()->systemConfigKeyHandler.save(param));
    }

    /**
     * 更新key
     * @param param
     * @return
     */
    @PostMapping("update")
    public Result update(@Validated(value = {CommonUpdate.class, CommonValidate.class}) SystemConfigKeyParam param){
        return  handlerExecutor.execute(()->systemConfigKeyHandler.update(param));
    }

    /**
     * 根据位置id查找该位置下所有的key
     * @param param
     * @return
     */
    @PostMapping("queryKeyList")
    public Result queryPositionTree(SystemConfigKeyQueryParam param){
        return  handlerExecutor.execute(()->systemConfigKeyHandler.queryConfigKeyAll(param));
    }

    /**
     * 根据位置id查找该位置下所有的key
     * @param id
     * @return
     */
    @PostMapping("delete")
    public Result delete(@RequestParam List<Long> id){
        return  handlerExecutor.execute(()->systemConfigKeyHandler.delete(id));
    }
}
